package dyyx;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public class MDCTest {
	
    private static Logger logger = LoggerFactory.getLogger(MDCTest.class);

	public static void main(String[] args) throws Exception {	
		
		// MDC ( Mapped Diagnostic Contexts )
		
		MDC.put("traceId", UUID.randomUUID().toString());
        logger.info("MDCTest");
        
        // MDC.getCopyOfContextMap();
        
        Task task = new Task();
        task.setName("task-thread");
        task.start();
        task.join();
        
        // [traceId = %X{traceId}] 
        
        logger.info("MDCTest2");

        MDC.clear();
        logger.info("MDCTest after clear");
        MDC.remove("traceId");
        logger.info("MDCTest after remove");   
	}
	
	private static class Task extends Thread{
		public void run(){
			logger.info("log in "+this.getName());
		}
	}
}
